package com.m3839.sdk.ym.ext

import android.app.Activity
import android.app.DialogFragment
import android.content.Context
import android.view.View

/**
 * @description: ResourceExt
 *
 * @author ChenBaoyang
 * @date 6/4/21 16:58
 */

private const val RES_ID = "id"
private const val RES_STRING = "string"
private const val RES_DRAWABLE = "drawable"
private const val RES_LAYOUT = "layout"
private const val RES_STYLE = "style"
private const val RES_COLOR = "color"
private const val RES_DIMEN = "dimen"
private const val RES_ANIM = "anim"
private const val RES_MENU = "menu"

fun DialogFragment.getId(resName: String?): Int {
    return getResId(resName, RES_ID)
}

fun DialogFragment.getStringId(resName: String?): Int {
    return getResId(resName, RES_STRING)
}

fun DialogFragment.getDrawableId(resName: String?): Int {
    return getResId(resName, RES_DRAWABLE)
}

fun DialogFragment.getLayoutId(resName: String?): Int {
    return getResId(resName, RES_LAYOUT)
}

fun DialogFragment.getStyleId(resName: String?): Int {
    return getResId(resName, RES_STYLE)
}

fun DialogFragment.getColorId(resName: String?): Int {
    return getResId(resName, RES_COLOR)
}

fun DialogFragment.getDimenId(resName: String?): Int {
    return getResId(resName, RES_DIMEN)
}

fun DialogFragment.getAnimId(resName: String?): Int {
    return getResId(resName, RES_ANIM)
}

fun DialogFragment.getMenuId(resName: String?): Int {
    return getResId(resName, RES_MENU)
}

fun DialogFragment.getResId(
    resName: String?,
    defType: String?
): Int {
    return resources.getIdentifier(resName, defType, activity.packageName)
}

/************************** 以下是View的资源扩展函数 ****************************/

fun View.getLayoutId(resName: String?): Int {
    return getResId(resName, RES_LAYOUT)
}

fun View.getResId(
    resName: String?,
    defType: String?
): Int {
    return resources.getIdentifier(resName, defType, context.packageName)
}

/************************** 以下是Activity的资源扩展函数 ****************************/
fun Activity.getId(resName: String?): Int {
    return getResId(resName, RES_ID)
}

fun Activity.getLayoutId(resName: String?): Int {
    return getResId(resName, RES_LAYOUT)
}

fun Context.getResId(
    resName: String?,
    defType: String?
): Int {
    return resources.getIdentifier(resName, defType, packageName)
}


